#ifndef __SVR_SKELETON_H__
#define __SVR_SKELETON_H__

#include <soar.h>

#include <atmi.h>
#include <Uunix.h>
#include <userlog.h>

__BEGIN_DECLS

#define DEFINE_SERVICE(svc)                                     \
extern int SVC_FUNC_##svc(char *request, char *respond);        \
                                                                \
void SVC_##svc _((TPSVCINFO *rqst))                             \
{                                                               \
    int ret;                                                    \
    char *msg_return;                                           \
																\
    CLR_BUF(respond);											\
    if(strlen(rqst->data) >= MSG_SIZE)                          \
    {															\
        userlog("rqst->data(%d) too long\n",                    \
                strlen(rqst->data));                            \
        para_put_item(respond, SOAR_ERR_PARA);                  \
    }                                                           \
    else                                                        \
    {                                                           \
        strcpy(request, rqst->data);                            \
        SVC_FUNC_##svc(request, respond);                       \
    }															\
    if(!(msg_return=tpalloc("STRING", NULL,                     \
           strlen(respond)+128)))                               \
    {                                                           \
        userlog("tpalloc failed: %s\n", tpstrerror(tperrno));   \
        ret=TPEXIT;                                             \
    }                                                           \
    else                                                        \
    {                                                           \
        CLR_BUF(msg_return);                                    \
        strcpy(msg_return, respond);                            \
        ret=TPSUCCESS;                                          \
    }                                                           \
    tpreturn(ret, 0, msg_return, 0L, 0);                        \
}

__END_DECLS

#endif
